package com.example.aichat.controller;

import com.example.aichat.dto.ChatRequest;
import com.example.aichat.service.OllamaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter;

@RestController
@RequestMapping("/api")
public class ChatController {

    @Autowired
    private OllamaService ollamaService;

    @PostMapping(value = "/stream_chat", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseBodyEmitter streamChat(@RequestBody ChatRequest request) {
        System.out.println("request: " + request.getContent());
        ResponseBodyEmitter emitter = new ResponseBodyEmitter(Long.MAX_VALUE);

        ollamaService.streamChat(request.getContent(), emitter);
        return emitter;
    }
}